from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from weibo_account import user,password

chrome=webdriver.Chrome()
chrome.get('https://weibo.com')
locator = ('tag name', 'input')
WebDriverWait(chrome, 20, 0.5).until(EC.presence_of_all_elements_located(locator))
# ele=chrome.find_element_by_link_text('新闻')
# print(ele)
# ele.click()
# chrome.implicitly_wait(4)
# print(chrome.page_source)
chrome.find_element_by_id('loginname').send_keys(user)
chrome.find_element_by_name('password').send_keys(password)
chrome.get_cookie()
login=chrome.find_element_by_xpath("//div[@class='W_login_form']/div[@class='info_list login_btn']/a")
login.click()
locator=(By.LINK_TEXT, '梦丨华尔兹丿')
WebDriverWait(chrome, 20, 0.5).until(EC.presence_of_all_elements_located(locator))
send_weibo=chrome.find_elements_by_xpath("//div[@class='gn_set_list'][3]/a")
send_weibo.click()
chrome.implicitly_wait(1)
send_topic=chrome.find_element_by_xpath("//div[@class='kind']/a/[4]")
send_topic.click()
chrome.find_elements_by_xpath("//div[@class='topic_ipt']/input").send_key('爬虫')
confirm=chrome.find_elements_by_xpath("//ul[@class='topic_list']/li[1]")
confirm.click()
chrome.find_element_by_class_name('W_input').send_keys('用selenium自动发送的微博')
send=chrome.find_elements_by_xpath("//div[@class='func']/a")
send.click()
# js="window.open('https://www.douban.com')"
# chrome.execute_script(js)
